package com.wyix.entity;

/**
 * 电动车类继承自Car类
 *
 * @author wangdx
 * @since 2025/8/1
 */
public class ElectricCar extends Car {
    private double batteryCapacity; // 电池容量(kWh)
    private int maxRange; // 最大续航里程(km)

    // 构造方法
    public ElectricCar(String brand, String model, double price,
                       String color, int productionYear,
                       double batteryCapacity, int maxRange) {
        // 调用父类构造方法
        super(brand, model, price, color, productionYear);
        this.batteryCapacity = batteryCapacity;
        this.maxRange = maxRange;
    }

    // 电动车特有方法
    public void charge() {
        System.out.println(getBrand() + getModel() + "正在充电，当前电池容量" + batteryCapacity + "kWh");
    }

    // 重写父类方法（多态体现）
    @Override
    public void startEngine() {
        System.out.println(getBrand() + getModel() + "的电动机启动了，安静无声");
    }

    // 新增计算每公里成本的方法
    public double calculateCostPerKm(double electricityPrice) {
        return (batteryCapacity / maxRange) * electricityPrice;
    }

    // Getter和Setter
    public double getBatteryCapacity() {
        return batteryCapacity;
    }

    public void setBatteryCapacity(double batteryCapacity) {
        this.batteryCapacity = batteryCapacity;
    }

    public int getMaxRange() {
        return maxRange;
    }

    public void setMaxRange(int maxRange) {
        this.maxRange = maxRange;
    }

    // 重写toString方法
    @Override
    public String toString() {
        return "ElectricCar{" +
                "品牌='" + getBrand() + '\'' +
                ", 型号='" + getModel() + '\'' +
                ", 价格=" + getPrice() +
                ", 电池容量=" + batteryCapacity + "kWh" +
                ", 最大续航=" + maxRange + "km" +
                '}';
    }
}